<template>
  <!-- <div>#ca8687</div> -->
  <el-container class="header-container">
    <!-- 头部 -->
    <el-header>
      <div>
        <img src="../assets/img/1.jpg" alt="" />
        <span>电商管理系统</span>
      </div>
      <el-button size="small" plain type="primary" @click="backt"
        >退出</el-button
      >
    </el-header>
    <el-container>
      <!-- 左侧 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <!-- 折叠菜单 -->
        <div class="fold" @click="float">|||</div>
        <!-- 侧边导航菜单 -->
        <el-menu
          background-color="#FFCCCC"
          text-color="#FFFFFF"
          active-text-color="#804040"
          :unique-opened="true"
          :collapse="isCollapse"
          :collapse-transition="false"
          :router="true"
          :default-active="$route.path"
        >
          <el-submenu
            :index="item.id + ''"
            v-for="item in menulist"
            :key="item.id"
          >
            <template slot="title">
              <i :class="icons[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级导航 -->
            <el-menu-item
              v-for="suitem in item.children"
              :index="'/' + suitem.path"
              :key="suitem.id"
            >
              <template slot="title">
                <i class="el-icon-menu"></i>
                <span>{{ suitem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体 -->
      <el-main>
        <!-- 欢迎语页面路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data() {
    return {
      // 图标
      icons: {
        125: "el-icon-s-custom",
        103: "el-icon-s-promotion",
        101: "el-icon-s-goods",
        102: "el-icon-s-claim",
        145: "el-icon-s-data",
      },
      // 获取菜单
      menulist: [],
      // 菜单是否折叠(false为不折叠)
      isCollapse: false,
    };
  },
  created() {
    this.getMenuList();
  },
  methods: {
    // 退出按钮
    backt() {
      window.sessionStorage.clear();
      this.$router.push("/login"); //重定向
    },
    // 获取菜单
    async getMenuList() {
      const { data: res } = await this.$http.get("menus");
      if (res.meta.status != 200) return this.$message.error(res.meta.msg);
      this.menulist = res.data;
    },
    // 菜单是否折叠方法
    float() {
      this.isCollapse = !this.isCollapse;
    },
  },
};
</script>
<style lang="less" scoped>
.header-container {
  height: 100%;
}
.el-header {
  background-color: #ff9999;
  // background-color: #ff6262;
  display: flex;
  justify-content: space-between;
  // padding: 0px;
  align-items: center;
  color: aliceblue;
  font-size: 18px;
  div {
    display: flex;
    align-items: center;
    img {
      width: 50px;
      height: 50px;
    }
    span {
      margin-left: 15px;
    }
  }
}
.el-menu {
  border: 0px;
}
.el-container {
  background-color: #ffcccc;
}
.el-main {
  background-color: #fbebea;
}
// 折叠导航栏
.fold {
  background-color: #9d6c6c;
  text-align: center;
  line-height: 25px;
  letter-spacing: 2px;
  color: white;
  cursor: pointer;
}
</style>
